package com.dxy.netty.handlerchain;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @Description nety服务器handler
 * @author xiao tang
 * @version 1.0.0
 * @createTime 2022年09月10日
 */
public class NettyHandlerChainServerHandler extends SimpleChannelInboundHandler<Long> {
    // 被调用多次
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {
        System.out.println("从客户端" + ctx.channel().remoteAddress() + "读取到long: " + msg);
        // 给客户端回送消息
        ctx.writeAndFlush(98765L);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}